
#include "CustomerRecord.h"

namespace AirlineRes
{

CustomerRecord::CustomerRecord
(
  std::string const& _passportNo,
  std::string const& _firstName,
  std::string const& _lastName,
  TimeDate    const& _dateOfBirth,
  std::string const& _email,
  std::string const& _phoneNo
)
: m_passportNo( _passportNo ),
  m_firstName( _firstName ),
  m_lastName( _lastName ),
  m_dateOfBirth( _dateOfBirth ),
  m_email( _email ),
  m_phoneNo( _phoneNo )
{
}

Record::RecordIOResult CustomerRecord::LoadRecord( std::istream& _stream )
{
  // TODO: Validation and error handling.
  std::string dob;
  _stream >> std::skipws;   // Skip whitespace.
  _stream >> m_id >> m_passportNo >> m_firstName >> m_lastName >> dob >> m_email >> m_phoneNo;
  _stream >> std::noskipws; // Reset stream state. 

  m_dateOfBirth.SetTime( dob );

  return Record::RecordIOResult_Success;
}

Record::RecordIOResult CustomerRecord::WriteRecord( std::ostream& _stream ) const
{
  _stream
    << m_id << " "
    << m_passportNo << " "
    << m_firstName << " "
    << m_lastName << " "
    << m_dateOfBirth.GetDDMMYYYY() << " "
    << m_email << " "
    << m_phoneNo << "\n";

  return Record::RecordIOResult_Success;
}
    

} // namespace AirlineRes
